<template>
    <!--地图挂载dom-->
    <div id="map">
    </div>
</template>

<script>
    //引入依赖
    import Map from 'ol/Map';
    import View from 'ol/View';
    import WKT from 'ol/format/WKT';
    import {OSM, Vector as VectorSource} from 'ol/source';
    import {Tile as TileLayer, Vector as VectorLayer} from 'ol/layer';
    export default {
        name: "WktLayer",
        mounted() {
            const raster = new TileLayer({
                source: new OSM(),
            });

            const wkt =
                'POLYGON((10.689 -25.092, 34.595 ' +
                '-20.170, 38.814 -35.639, 13.502 ' +
                '-39.155, 10.689 -25.092))';//wkt表示面的情况下，也是需要闭合的

            //指定数据加载的读取格式wkt
            const format = new WKT();

            //用wkt读取要素信息
            const feature = format.readFeature(wkt, {
                dataProjection: 'EPSG:4326',//数据的投影坐标
                featureProjection: 'EPSG:3857',//读取之后的要素投影的坐标
            });
            //矢量图层
            const vector = new VectorLayer({
                source: new VectorSource({
                    features: [feature],
                }),
            });
            //地图渲染
            const map = new Map({
                layers: [raster, vector],
                target: 'map',
                view: new View({
                    center: [2952104.0199, -3277504.823],//中心点使用的是平面投影3857
                    zoom: 4,
                }),
            });
        },
        methods: {
        }
    }
</script>

<style scoped>

</style>